package com.bookstore.Service.impl;

import com.bookstore.Domain.Person;
import com.bookstore.Service.PersonService;
import com.bookstore.mapper.PersonMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author 未来
 */
@Service
public class PersonServiceImpl implements PersonService {
    private final PersonMapper personMapper;

    @Autowired
    public PersonServiceImpl(PersonMapper personMapper) {
        this.personMapper = personMapper;
    }


    @Override
    public List<Person> getAllPerson() {
        return personMapper.selectList(null);
    }

    @Override
    public boolean addPerson(Person person) {
        return personMapper.insert(person) > 0;
    }

    @Override
    public boolean deletePesson(int[] ids) {
        // 将int数组转换为List
        List<Integer> idList = Arrays.stream(ids).boxed().collect(Collectors.toList());
        System.out.println(idList.size());
        return personMapper.deleteBatchIds(idList) > 0;
    }
}
